package com.huilian.iotbox.admin.wap.controller;

import com.huilian.iotbox.admin.wap.service.DisplayRackItemService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.dto.DisplayRackItemDto;
import com.huilian.iotbox.data.enums.RoleEnum;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author chenqiwen
 * @CreateDate: 2022-01-14-18-29
 * @Description:
 */

@RestController
@RequestMapping("/api/displayRackItem")
public class DisplayRackItemController extends UserInfoController {
    @Autowired
    private DisplayRackItemService displayRackItemService;

    @GetMapping("/findAllBoundGoodsStockByDeviceId")
    public ServerResponse findAllBoundGoodsStockByDeviceId(DisplayRackItemDto displayRackItemDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        displayRackItemDto.setUserInfo(userInfo);
        if (RoleEnum.SUB_ACCOUNT.getRoleId().equals(userInfo.getRoleId())) {
            displayRackItemDto.setUserId(userInfo.getParentId());
        } else {
            displayRackItemDto.setUserId(userInfo.getId());
        }
        return displayRackItemService.findAllBoundDisplayRackItemByDeviceId(displayRackItemDto);
    }


    /**
     * DisplayRackItemDto displayRackItemDto
     *
     * @param displayRackItemDto
     * @param request
     * @return
     */
    @GetMapping("/findAllGoodsStockAwardByDeviceId")
    public ServerResponse findAllGoodsStockAwardByDeviceId(DisplayRackItemDto displayRackItemDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        displayRackItemDto.setUserInfo(userInfo);
        return displayRackItemService.findAllGoodsStockAwardByDeviceId(displayRackItemDto);
    }

    @GetMapping("/findVendingMachine")
    public  ServerResponse findVendingMachine(DisplayRackItemDto displayRackItemDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        displayRackItemDto.setUserInfo(userInfo);
        return ServerResponse.createBySuccess(displayRackItemService.findVendingMachine(displayRackItemDto));
    }

    @PostMapping("/updateByIdAndUserId")
    public  ServerResponse updateByIdAndUserId(@RequestBody DisplayRackItemDto displayRackItemDto, HttpServletRequest request) throws Exception {
        UserInfo userInfo = super.getLoginUserInfo(request);
        displayRackItemDto.setUserInfo(userInfo);
        if (RoleEnum.SUB_ACCOUNT.getRoleId().equals(userInfo.getRoleId())) {
            displayRackItemDto.setUserId(userInfo.getParentId());
        } else {
            displayRackItemDto.setUserId(userInfo.getId());
        }
        return ServerResponse.createBySuccess(displayRackItemService.updateByIdAndUserId(displayRackItemDto));
    }

    @PostMapping("/updatePrice")
    public  ServerResponse updatePrice(@RequestBody DisplayRackItemDto displayRackItemDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        displayRackItemDto.setUserInfo(userInfo);
        if (RoleEnum.SUB_ACCOUNT.getRoleId().equals(userInfo.getRoleId())) {
            displayRackItemDto.setUserId(userInfo.getParentId());
        } else {
            displayRackItemDto.setUserId(userInfo.getId());
        }
        return ServerResponse.createBySuccess(displayRackItemService.updatePrice(displayRackItemDto));
    }

    @GetMapping("/findInventoryByDisplayRackId")
    public  ServerResponse findInventoryByDisplayRackId(DisplayRackItemDto displayRackItemDto) throws Exception {
        return ServerResponse.createBySuccess(displayRackItemService.findInventoryByDisplayRackId(displayRackItemDto.getDisplayRackId()));
    }
    @PostMapping("/oneClickClearance")
    public  ServerResponse oneClickClearance(@RequestBody  DisplayRackItemDto displayRackItemDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        displayRackItemDto.setUserInfo(userInfo);
        if (RoleEnum.SUB_ACCOUNT.getRoleId().equals(userInfo.getRoleId())) {
            displayRackItemDto.setUserId(userInfo.getParentId());
        } else {
            displayRackItemDto.setUserId(userInfo.getId());
        }
        displayRackItemService.oneClickClearance(displayRackItemDto);
        return ServerResponse.createBySuccess();
    }
    @PostMapping("/fillItUpWithOneKey")
    public  ServerResponse fillItUpWithOneKey(@RequestBody  DisplayRackItemDto displayRackItemDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        displayRackItemDto.setUserInfo(userInfo);
        if (RoleEnum.SUB_ACCOUNT.getRoleId().equals(userInfo.getRoleId())) {
            displayRackItemDto.setUserId(userInfo.getParentId());
        } else {
            displayRackItemDto.setUserId(userInfo.getId());
        }
        displayRackItemService.fillItUpWithOneKey(displayRackItemDto);
        return ServerResponse.createBySuccess();
    }
    @GetMapping("/findCommodityByHierarchy")
    public  ServerResponse findCommodityByHierarchy(DisplayRackItemDto displayRackItemDto) {
        return ServerResponse.createBySuccess(displayRackItemService.findCommodityByHierarchy(displayRackItemDto));
    }
    @PostMapping("/multiAisleFilling")
    public  ServerResponse multiAisleFilling(@RequestBody  DisplayRackItemDto displayRackItemDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        displayRackItemDto.setUserInfo(userInfo);
        if (RoleEnum.SUB_ACCOUNT.getRoleId().equals(userInfo.getRoleId())) {
            displayRackItemDto.setUserId(userInfo.getParentId());
        } else {
            displayRackItemDto.setUserId(userInfo.getId());
        }
        displayRackItemService.multiAisleFilling(displayRackItemDto);
        return ServerResponse.createBySuccess();
    }
    @PostMapping("/offTheShelves")
    public  ServerResponse offTheShelves(@RequestBody  DisplayRackItemDto displayRackItemDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        displayRackItemDto.setUserInfo(userInfo);
        if (RoleEnum.SUB_ACCOUNT.getRoleId().equals(userInfo.getRoleId())) {
            displayRackItemDto.setUserId(userInfo.getParentId());
        } else {
            displayRackItemDto.setUserId(userInfo.getId());
        }
        return ServerResponse.createBySuccess(displayRackItemService.offTheShelves(displayRackItemDto));
    }

    @GetMapping("/findTakeStockOfOutOfStock")
    public  ServerResponse findTakeStockOfOutOfStock(DisplayRackItemDto displayRackItemDto) {
        return ServerResponse.createBySuccess(displayRackItemService.findTakeStockOfOutOfStock(displayRackItemDto));
    }

    @GetMapping("/findOutOfStockDetails")
    public  ServerResponse findOutOfStockDetails(DisplayRackItemDto displayRackItemDto) {
        return ServerResponse.createBySuccess(displayRackItemService.findOutOfStockDetails(displayRackItemDto));
    }



    @GetMapping("/sendInspectionTrackMotor")
    public  ServerResponse sendInspectionTrackMotor(DisplayRackItemDto displayRackItemDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        Integer userId = userInfo.getId();
        displayRackItemDto.setUserInfo(userInfo);
        if (RoleEnum.SUB_ACCOUNT.getRoleId().equals(userInfo.getRoleId())) {
            displayRackItemDto.setUserId(userInfo.getParentId());
        } else {
            displayRackItemDto.setUserId(userInfo.getId());
        }

        return ServerResponse.createBySuccess(displayRackItemService.sendInspectionTrackMotor(displayRackItemDto,userId));
    }

    @PostMapping("/updateOffEnabledById")
    public  ServerResponse updateOffEnabledById(@RequestBody  DisplayRackItemDto displayRackItemDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        displayRackItemDto.setUserInfo(userInfo);
        if (RoleEnum.SUB_ACCOUNT.getRoleId().equals(userInfo.getRoleId())) {
            displayRackItemDto.setUserId(userInfo.getParentId());
        } else {
            displayRackItemDto.setUserId(userInfo.getId());
        }
        return ServerResponse.createBySuccess(displayRackItemService.updateOffEnabledById(displayRackItemDto));
    }
    @PostMapping("/updateAllOffEnabledById")
    public  ServerResponse updateAllOffEnabledById(@RequestBody  DisplayRackItemDto displayRackItemDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        displayRackItemDto.setUserInfo(userInfo);
        if (RoleEnum.SUB_ACCOUNT.getRoleId().equals(userInfo.getRoleId())) {
            displayRackItemDto.setUserId(userInfo.getParentId());
        } else {
            displayRackItemDto.setUserId(userInfo.getId());
        }
        return ServerResponse.createBySuccess(displayRackItemService.updateAllOffEnabledById(displayRackItemDto));
    }
    @PostMapping("/updateAliasById")
    public  ServerResponse updateAliasById(@RequestBody  DisplayRackItemDto displayRackItemDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        displayRackItemDto.setUserInfo(userInfo);
        if (RoleEnum.SUB_ACCOUNT.getRoleId().equals(userInfo.getRoleId())) {
            displayRackItemDto.setUserId(userInfo.getParentId());
        } else {
            displayRackItemDto.setUserId(userInfo.getId());
        }
        return ServerResponse.createBySuccess(displayRackItemService.updateAliasById(displayRackItemDto));
    }

    @PostMapping("/batchModifyCommodity")
    public  ServerResponse batchModifyCommodity(@RequestBody  DisplayRackItemDto displayRackItemDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        displayRackItemDto.setUserInfo(userInfo);
        if (RoleEnum.SUB_ACCOUNT.getRoleId().equals(userInfo.getRoleId())) {
            displayRackItemDto.setUserId(userInfo.getParentId());
        } else {
            displayRackItemDto.setUserId(userInfo.getId());
        }
        return displayRackItemService.batchModifyCommodity(displayRackItemDto);
    }
}
